<template>
    <el-tree
      :data="category"
      :props="defaultProps"
      node-key="catId"
      :expand-on-click-node="false"
      :default-expanded-keys="expanded"
      @node-click="handleCategoryNodeClick"
    >
    </el-tree>
</template>


<script>
import { tree } from "@/api/product/product.js";
export default {
    data() {
    return {
      expanded: [], // 默认展开的节点，防止删除节点后树收缩了
      category: [],
      defaultProps: {
        children: "childrens",
        label: "name",
      },
    };
  },
  created() {
    this.getProductCategoryTree();
  },
  methods: {
    handleCategoryNodeClick(data, node) {
        this.$emit('tree-node-click', data, node);
      // console.log(data);
    },
    getProductCategoryTree() {
      tree()
        .then((res) => {
          this.category = res.data;
        })
        .catch((err) => console.log(err));
    },
  },
}
</script>